package com.ywl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywl.pojo.Admin;
import com.ywl.service.AdminService;
import com.ywl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DL5O
 * @version 1.0
 */
@Api(tags = "管理员控制器")
@RestController//   不是@Controller，异步Controller
@RequestMapping("/sms/adminController")
public class AdminController {

    @Autowired
    AdminService adminService;


    /**
     * 删除单个或者多条管理员用户
     * @param ids
     * @return
     */
    //DELETE /sms/adminController/deleteAdmin
    @ApiOperation("删除单个或者多条管理员用户")
    @DeleteMapping("/deleteAdmin")
    public Result deleteAdmin(@RequestBody List<Integer> ids){
        adminService.removeByIds(ids);
        return Result.ok();
    }



    //POST /sms/adminController/saveOrUpdateAdmin
    @ApiOperation("更新或者新增管理员")
    @PostMapping("/saveOrUpdateAdmin")
    public Result saveOrUpdateAdmin(@RequestBody Admin admin){
        adminService.saveOrUpdate(admin);
        return Result.ok();
    }

    /**
     * 用户管理的分页查询
     * @param pageNo
     * @param pageSize
     * @param adminName
     * @return
     */
    //GET /sms/adminController/getAllAdmin/{pageNo}/{pageSize}
    @ApiOperation("用户管理的分页查询")
    @GetMapping("/getAllAdmin/{pageNo}/{pageSize}")
    public Result getAllAdmin(
            @ApiParam("页号") @PathVariable Integer pageNo,
            @ApiParam("页面大小")@PathVariable Integer pageSize,
            @ApiParam("管理员名字") String adminName
    ){
        Page<Admin> page = new Page<>(pageNo, pageSize);
        IPage<Admin> pageRs = adminService.getAdminOpr(page,adminName);
        return Result.ok(pageRs);
    }
}
